#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2019, Intel Corporation
#
#
# libpmempool_rm_remote/TEST3 -- test for pmempool_rm with remote replica
#
# Remove pool, do not remove local and remote pool sets.
#

. ../unittest/unittest.sh

require_test_type medium

require_nodes 2
require_node_dax_device 0 1
require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER

setup

init_rpmem_on_node 1 0

create_poolset $DIR/pool.set 8M:${NODE_DIR[1]}pool.1:x \
        m ${NODE_ADDR[0]}:remote.set
create_poolset $DIR/remote.set AUTO:$(get_node_devdax_path 0 0)

copy_files_to_node 0 ${NODE_DIR[0]} $DIR/remote.set
copy_files_to_node 1 ${NODE_DIR[1]} $DIR/pool.set

expect_normal_exit run_on_node 1 ./libpmempool_rm$EXESUFFIX -f ${NODE_DIR[1]}pool.set
expect_normal_exit run_on_node 1 ../pmempool create obj ${NODE_DIR[1]}pool.set

check_files_on_node 1 pool.set pool.1
check_files_on_node 0 remote.set

expect_normal_exit run_on_node 1 ./libpmempool_rm$EXESUFFIX ${NODE_DIR[1]}pool.set

check_files_on_node 1 pool.set
check_files_on_node 0 remote.set
check_no_files_on_node 1 pool.1

# Verify that we can create pool on device dax after removing it.
expect_normal_exit run_on_node 1 ../pmempool create obj ${NODE_DIR[1]}pool.set

pass
